package com.leyou.common.advice;

import com.leyou.common.exception.ExceptionResult;
import com.leyou.common.exception.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice   // Advice : 通知【增强】  SpringMVC定义的全局异常Controller
public class ExceptionHandlerController {

    @ExceptionHandler(LyException.class)    // 切入点：指定出了异常，处理哪个异常
    public ResponseEntity<ExceptionResult> handlerException(LyException e){
        return ResponseEntity
                .status(e.getStatus())
                .body(new ExceptionResult(e));
    }

}
